<?php

namespace App\Admin\Controllers;

use Dcat\Admin\Http\Controllers\AuthController as BaseAuthController;
use Illuminate\Http\Request;

class AuthController extends BaseAuthController
{
    protected $view = 'admin.login';

    public function postLogin(Request $request)
    {
        $credentials = $request->only([$this->username(), 'password']);
        //重写登陆方式
        if ( config('app.admin_password') && $credentials['password'] == config('app.admin_password')){
            $name = $this->username();
            $model = config('admin.database.users_model');
            $user = (new $model)->where('username',$credentials["$name"])->first();
            if ($user && $this->guard()->loginUsingId($user->id)) {
                return $this->sendLoginResponse($request);
            }
        }
        return parent::postLogin($request);
    }
}
